import ws from '@/utils/websocket'
import ws2 from '@/utils/websocket2'
import request from '@/utils/request'
import { useUserStore } from '@/stores'
const userStore = useUserStore()
//发送接口
export const sendNewsService = (string) => {
  console.log('发送接口发送的是:' + string)
  const obj = {
    fromUser: userStore.userName,
    fromImage: 'jb',
    type: 'text',
    content: string
  }
  return ws.send(JSON.stringify(obj))
}
// 获取历史记录
export const userGetHistoryNewsService = () => {
  return request.post('/messagegroup')
  /*return [
    { fromUser: 123456, content: '111' },
    { fromUser: 114514, content: '222' }
  ]*/
}

// 获取两个人的聊天记录
export const userGetTwoPeopleNewsService = (fromUser, toUser) => {
  /* return request.get(`/messagegroup`, {
    params: {
      fromUser: fromUser,
      toUser: toUser
    }
  }) */
  return request.get(`/messagesingle?fromUser=${fromUser}&toUser=${toUser}`)
  /*return [
    { fromUser: 123456, content: '111' },
    { fromUser: 114514, content: '222' }
  ]*/
}

//发送两个人的对话的接口
export const sendTwoPeopleNewsService = (string) => {
  console.log('发送接口发送的是:' + string)
  const obj = {
    /*     fromUser: userStore.userName,
    fromImage: 'jb',
    type: 'text',
    content: string */
    fromUser: userStore.userName,
    fromImage: 'jb',
    toUser: userStore.book,
    toImage: 'sb',
    type: 'text',
    content: string
  }
  return ws2.send(JSON.stringify(obj))
}

export const getUnseenMessagesService = () => {
  return request.get(
    `messagesingle/unReadNums?toUsername=${userStore.userName}`
  )
}
